﻿using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Collections.Generic;
using System.Web.Mvc;
using System.Globalization;
using OutSource.Common.MarketSense;

namespace QianJin.Views
{
    public static class ViewUtility
    {
        static public string MapImagePath(string imgName)
        {
            return string.Format(CultureInfo.InvariantCulture, "/content/{0}/{1}", MarketSense.CurrentMarket, imgName);
        }

        static public string GetProductIntroUrl(string prodId)
        {
            return string.Format(CultureInfo.InvariantCulture, @"/Products/{0}/{1}/intro.htm", prodId, MarketSense.CurrentMarket);
        }
        static public string GetProductDetailUrl(string prodId)
        {
            return string.Format(CultureInfo.InvariantCulture, @"/Products/{0}/{1}/detail.htm", prodId, MarketSense.CurrentMarket);
        }

        static public string GetProductImageUrl(string prodId)
        {
            return string.Format(CultureInfo.InvariantCulture, @"/Products/{0}/thumbnail.jpg", prodId);
        }
        static public string GetProductDetailImageUrl(string prodId)
        {
            return string.Format(CultureInfo.InvariantCulture, @"/Products/{0}/detail.jpg", prodId);
        }

        static public string MapCssPath(string file)
        {
            return string.Format(CultureInfo.InvariantCulture, @"/content/{0}/{1}", MarketSense.CurrentMarket, file); 
        }
    }

    public class BaseView<T>: ViewPage<T> where T : BaseViewData
    {
        protected string GetString(string id)
        {
            return (string)this.GetGlobalResourceObject("qianjin", id);
        }


        public string GetAddToShoppingCartUrl(string prodId)
        {
            return Url.Action("AddShoppingItem", "Shopping", new { productId = prodId, returnUrl = this.Context.Request.Url.OriginalString });
        }

        public string GetRemoveFromShoppingCartUrl(string prodId)
        {
            return Url.Action("RemoveShoppingItem", "Shopping", new { productId = prodId, returnUrl = this.Context.Request.Url.OriginalString });
        }
    }
}
